home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vb_g_prt / prtsetup.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-06  |  9.1 KB  |  263 lines

  1. VERSION 2.00
  2. Begin Form PrtSetupForm 
  3.    BackColor       =   &H8000000F&
  4.    Caption         =   "Print Setup"
  5.    ClientHeight    =   2235
  6.    ClientLeft      =   1185
  7.    ClientTop       =   2520
  8.    ClientWidth     =   6060
  9.    Height          =   2640
  10.    Left            =   1125
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   2235
  15.    ScaleWidth      =   6060
  16.    Top             =   2175
  17.    Width           =   6180
  18.    Begin TextBox txtTempOrientation 
  19.       Height          =   372
  20.       Left            =   120
  21.       TabIndex        =   9
  22.       Text            =   "txtTempOrientation"
  23.       Top             =   2520
  24.       Visible         =   0   'False
  25.       Width           =   5172
  26.    End
  27.    Begin TextBox txtTempPrinter 
  28.       Height          =   372
  29.       Left            =   120
  30.       TabIndex        =   8
  31.       Text            =   "txtTempPrinter"
  32.       Top             =   2160
  33.       Visible         =   0   'False
  34.       Width           =   5172
  35.    End
  36.    Begin Frame Frame1 
  37.       BackColor       =   &H00C0C0C0&
  38.       Caption         =   "Orientation"
  39.       Height          =   1092
  40.       Left            =   4200
  41.       TabIndex        =   5
  42.       Top             =   960
  43.       Width           =   1692
  44.       Begin OptionButton Option1 
  45.          BackColor       =   &H00C0C0C0&
  46.          Caption         =   "Landscape"
  47.          Height          =   252
  48.          Index           =   1
  49.          Left            =   120
  50.          TabIndex        =   7
  51.          Top             =   720
  52.          Width           =   1452
  53.       End
  54.       Begin OptionButton Option1 
  55.          BackColor       =   &H00C0C0C0&
  56.          Caption         =   "Portrait"
  57.          Height          =   252
  58.          Index           =   0
  59.          Left            =   120
  60.          TabIndex        =   6
  61.          Top             =   360
  62.          Width           =   1452
  63.       End
  64.    End
  65.    Begin ListBox List1 
  66.       Height          =   1785
  67.       Left            =   120
  68.       TabIndex        =   4
  69.       Top             =   336
  70.       Width           =   3855
  71.    End
  72.    Begin CommandButton cmdSetup 
  73.       Caption         =   "&Setup..."
  74.       Height          =   348
  75.       Left            =   4200
  76.       TabIndex        =   2
  77.       Top             =   1728
  78.       Width           =   1332
  79.    End
  80.    Begin CommandButton cmdCancel 
  81.       Cancel          =   -1  'True
  82.       Caption         =   "&Cancel"
  83.       Height          =   348
  84.       Left            =   4200
  85.       TabIndex        =   1
  86.       Top             =   576
  87.       Width           =   1332
  88.    End
  89.    Begin CommandButton cmdOK 
  90.       Caption         =   "&OK"
  91.       Default         =   -1  'True
  92.       Height          =   348
  93.       Left            =   4200
  94.       TabIndex        =   0
  95.       Top             =   144
  96.       Width           =   1332
  97.    End
  98.    Begin Label Label1 
  99.       BackColor       =   &H8000000F&
  100.       Caption         =   "&Printer:"
  101.       Height          =   204
  102.       Left            =   120
  103.       TabIndex        =   3
  104.       Top             =   96
  105.       Width           =   972
  106.    End
  107. '----------------------------------------------------------------
  108. 'Copyright 1994   Unger Business Systems  All Rights Reserved
  109. 'This code is distributed as shareware.  If you use it, you
  110. 'are required by law to register it.  Please contact Unger
  111. 'Business Systems at 11926 Barrett Brae, Houston, TX 77072-4004
  112. 'or call (713) 498-8517.  Registration fee is $20.00 US
  113. 'See the README.TXT file for more information
  114. 'All code, forms, modules, controls, etc. are provided without
  115. 'warranty or liability
  116. '----------------------------------------------------------------
  117. Option Explicit
  118. Dim PrinterArray$(1 To 20)
  119. Dim TempPrtOrientStr$
  120. Sub cmdCancel_Click ()
  121.    txtTempPrinter = ""
  122.    Me.Hide
  123. End Sub
  124. Sub cmdOK_Click ()
  125.    Me.Hide
  126. End Sub
  127. Sub cmdSetup_Click ()
  128.     'can only happen if cmdSetup is made visible
  129.     Dim dev$, devname$, DevOutput$
  130.     Dim dm As DEVMODE, dmout As DEVMODE
  131.     Dim libhnd%
  132.     Dim bufsize%
  133.     Dim dminstring$, dmoutstring$
  134.     Dim dminaddr&, dmoutaddr&, di%
  135.     dev$ = PrinterArray(List1.ItemData(List1.ListIndex))
  136.     If dev$ = "" Then Exit Sub
  137.     devname$ = GetDeviceName$(dev$)
  138.     DevOutput$ = GetDeviceOutput$(dev$)
  139.     ' Load the device driver library - exit if unavailable
  140.     libhnd% = LoadLibrary(GetDeviceDriver$(dev$) & ".drv")
  141.     If libhnd% = 0 Then
  142.        Beep
  143.        MsgBox "Unable to load driver " & GetDeviceDriver(dev) & ".drv", MB_ICONEXCLAMATION
  144.        Exit Sub
  145.     End If
  146.     bufsize% = agExtDeviceMode%(hWnd, libhnd%, 0, devname$, DevOutput$, agGetAddressForObject(dm), 0, 0)
  147.     dminstring$ = String$(bufsize%, 0)
  148.     dmoutstring$ = String$(bufsize%, 0)
  149.    'set orientation to current orientation
  150.     agCopyDataBynum agGetAddressForVBString&(dminstring$), agGetAddressForObject&(dm), 68
  151.     If TempPrtOrientStr = "LANDSCAPE" Then
  152.       dm.dmOrientation = DMORIENT_LANDSCAPE
  153.     Else
  154.       dm.dmOrientation = DMORIENT_PORTRAIT
  155.     End If
  156.     dm.dmFields = dm.dmFields Or DM_ORIENTATION
  157.     agCopyDataBynum agGetAddressForObject&(dm), agGetAddressForVBString&(dminstring$), 68
  158.     dminaddr& = agGetAddressForVBString&(dminstring$)
  159.     dmoutaddr& = agGetAddressForVBString&(dmoutstring$)
  160.     ' The output DEVMODE structure will reflect any changes
  161.     ' made by the printer setup dialog box.
  162.     ' Note that no changes will be made to the default
  163.     ' printer settings
  164.     di% = agExtDeviceMode(hWnd, libhnd%, dmoutaddr&, devname$, DevOutput$, dminaddr&, 0, DM_IN_BUFFER Or DM_IN_PROMPT Or DM_OUT_BUFFER)
  165.     If di = 1 Then 'OK
  166.        ' Copy the data buffer into the DEVMODE structure
  167.        agCopyDataBynum agGetAddressForVBString&(dmoutstring$), agGetAddressForObject&(dmout), 68
  168.        If dmout.dmOrientation = DMORIENT_PORTRAIT Then
  169.           TempPrtOrientStr = "PORTRAIT"
  170.        Else
  171.           TempPrtOrientStr = "LANDSCAPE"
  172.        End If
  173.     End If
  174. cleanup:
  175.    FreeLibrary (libhnd%)
  176. End Sub
  177. Sub Form_Load ()
  178.    Dim PrinterInfo$, I%, IPos%, OldPos%, Counter As Integer, DisplayStr$
  179.    Dim ThisPort$, ThisPrinter$, XtraInfo$, DevOutput$, NumOutputs%
  180.    Dim AddThis$, CurrentPrinter$
  181.    'note that everything here is set up so that it can be encapsulated
  182.    'in the SelectPrinter routine
  183.    CurrentPrinter = GetDeviceName(txtTempPrinter) & " on " & GetDeviceOutput(txtTempPrinter)
  184.    If txtTempOrientation = "PORTRAIT" Then
  185.       Option1(0) = True
  186.    Else
  187.       Option1(1) = True
  188.    End If
  189.    List1.Clear
  190.    PrinterInfo$ = Space$(255)
  191.    'Calling GetProfileString with 0& as the second parameter returns a list
  192.    'of all items in the "devices" section of WIN.INI
  193.    'These are separated by ASCII 0's and must be parsed
  194.    I% = GetProfileString("devices", 0&, "none", PrinterInfo$, Len(PrinterInfo$))
  195.    PrinterInfo$ = Left$(PrinterInfo$, I%)
  196.    If PrinterInfo$ = "none" Then
  197.       MsgBox "No Windows printers installed."
  198.       Exit Sub
  199.    End If
  200.    'MsgBox PrinterInfo
  201.    'parse out printers
  202.    'NOTE:  If a printer is installed for more than one port, it's string
  203.    'will look something like the following:
  204.    '              HP DeskJet 500,HPDSKJET,LPT1:,LPT2:
  205.    'Some of the code below is designed to create two strings,
  206.    'each with only one port
  207.    OldPos% = 1
  208.    Counter = 1
  209.    Do While 1
  210.       IPos% = InStr(OldPos%, PrinterInfo$, Chr$(0))
  211.       If IPos% > 0 Then
  212.          ThisPrinter$ = Mid$(PrinterInfo$, OldPos%, IPos% - OldPos%)
  213.          XtraInfo$ = Space$(255)
  214.          I% = GetProfileString("devices", ThisPrinter$, "none", XtraInfo$, Len(XtraInfo$))
  215.          ThisPrinter$ = ThisPrinter$ & "," & Left$(XtraInfo$, I%)
  216.          If Counter <= 20 Then
  217.             PrinterArray(Counter) = ThisPrinter
  218.          End If
  219.          DevOutput = GetDeviceOutput(ThisPrinter)
  220.          NumOutputs = GetNumDeviceOutputs(DevOutput)
  221.          For I = 1 To NumOutputs
  222.             AddThis = GetDeviceName(ThisPrinter$) & " on " & GetNumberedDeviceOutput(DevOutput, I)
  223.             PrinterArray(Counter) = GetDeviceName(ThisPrinter) & "," & GetDeviceDriver(ThisPrinter) & "," & GetNumberedDeviceOutput(DevOutput, I)
  224.             List1.AddItem AddThis
  225.             List1.ItemData(List1.NewIndex) = Counter
  226.             If PrinterArray(Counter) = CurrentPrinter Then
  227.                List1.ListIndex = Counter - 1
  228.             End If
  229.             Counter = Counter + 1
  230.          Next I
  231.          OldPos% = IPos% + 1
  232.       Else
  233.          Exit Do
  234.       End If
  235.    Loop
  236.    If List1.ListIndex < 0 Then List1.ListIndex = 0
  237. End Sub
  238. Sub List1_Click ()
  239.    txtTempPrinter = PrinterArray(List1.ListIndex + 1)
  240. End Sub
  241. Sub Option1_Click (Index As Integer)
  242.    If Index = 0 Then
  243.       txtTempOrientation = "PORTRAIT"
  244.    Else
  245.       txtTempOrientation = "LANDSCAPE"
  246.    End If
  247. End Sub
  248. Sub txtTempOrientation_Change ()
  249.    If txtTempOrientation = "PORTRAIT" Then
  250.       Option1(0) = True
  251.    Else
  252.       Option1(1) = True
  253.    End If
  254. End Sub
  255. Sub txtTempPrinter_Change ()
  256.    Dim I%
  257.    For I = 0 To List1.ListCount - 1
  258.       If List1.List(I) = txtTempPrinter Then
  259.          List1.ListIndex = I
  260.       End If
  261.    Next I
  262. End Sub
  263.